package cn.mccraft.uide.api.property;

import cn.mccraft.uide.api.property.key.Key;
import cn.mccraft.uide.api.property.value.Value;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import java.util.Optional;
import java.util.Set;

public abstract class PropertyHolderBase implements PropertyHolder {

    protected BiMap<Key<?>, Value<?>> properties = HashBiMap.create();

    @Override
    public Set<Key<?>> getKeys() {
        return properties.keySet();
    }

    @SuppressWarnings("unchecked")
    @Override
    public <V extends Value<?>> Optional<V> getValue(Key<V> key) {
        return Optional.ofNullable((V) properties.get(key));
    }

    @Override
    public <V extends Value<?>> void put(Key<V> key, V value) {
        properties.put(key, value);
    }

    @Override
    public boolean contains(Key<?> key) {
        return properties.containsKey(key);
    }

    @Override
    public void remove(Key<?> key) {
        properties.remove(key);
    }
}
